<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('修改讲师')}" />
    <th:block th:insert="~{include :: datetimepicker-css}" />
    <th:block th:insert="~{include :: summernote-css}" />
    <link href="/static/libs/layui-v2.6.8/css/layui.css" rel="stylesheet"/>
 </head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <form class="form-horizontal m" id="form-teacher-edit" th:object="${teacher}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group row">
            <div class="col-sm-6">
                <div class="form-group row">
                    <label class="col-sm-4 col-form-label text-sm-right">手机号</label>
                    <div class="col-sm-6">
                        <input th:if="*{id <= 0}" name="mobile"  th:value="*{mobile}" class="form-control" type="text">
                        <label th:if="*{id > 0}" class="col-form-label text-red" th:text="*{mobile}"></label>
                    </div>
                    <label class="col-sm-2 col-form-label text-sm-right">头像</label>
                </div>
                <div class="form-group row">
                    <label class="col-sm-4 col-form-label is-required text-sm-right">姓名</label>
                    <div class="col-sm-6">
                        <input name="name" th:value="*{name}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <img id="avatar-view" th:src="${teacher.avatar == null || teacher.avatar == ''?'/static/img/logo.png':teacher.avatar}" style="width: 100px;height: 100px;border:1px solid #eeeeee; cursor: pointer"/>
            </div>
            <div class="col-sm-3">
                <input id="avatar" th:value="*{avatar}" name="avatar" type="hidden">
                <label for="upload-avatar" class="btn btn-sm btn-danger"><i class="fa fa-image"></i> 上传头像</label>
                <input type="file" onchange="ImgUpdate()" style="display: none" value="" name="upload-avatar" id="upload-avatar" accept="image/*"/>
                <br>
                <strong class="text-orange">要求分辨率400X480</strong>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">出生日期</label>
            <div class="col-sm-2">
                <input name="birthday" th:value="*{birthday}" class="form-control" placeholder="请选择出生日期" type="text">
            </div>
            <label class="col-sm-2 col-form-label text-sm-right">籍贯</label>
            <div class="col-sm-2">
                <select name="nativePlace" class="form-control m-b" th:field="*{nativePlace}">
                    <option value="">籍贯</option>
                    <option value="北京">北京</option>
                    <option value="天津">天津</option>
                    <option value="河北">河北</option>
                    <option value="山西">山西</option>
                    <option value="内蒙古">内蒙古</option>
                    <option value="辽宁">辽宁</option>
                    <option value="吉林">吉林</option>
                    <option value="黑龙江">黑龙江</option>
                    <option value="上海">上海</option>
                    <option value="江苏">江苏</option>
                    <option value="浙江">浙江</option>
                    <option value="安徽">安徽</option>
                    <option value="福建">福建</option>
                    <option value="江西">江西</option>
                    <option value="山东">山东</option>
                    <option value="河南">河南</option>
                    <option value="湖北">湖北</option>
                    <option value="湖南">湖南</option>
                    <option value="广东">广东</option>
                    <option value="广西">广西</option>
                    <option value="海南">海南</option>
                    <option value="重庆">重庆</option>
                    <option value="四川">四川</option>
                    <option value="贵州">贵州</option>
                    <option value="云南">云南</option>
                    <option value="西藏">西藏</option>
                    <option value="陕西">陕西</option>
                    <option value="甘肃">甘肃</option>
                    <option value="青海">青海</option>
                    <option value="宁夏">宁夏</option>
                    <option value="新疆">新疆</option>
                    <option value="其它">其它</option>
                </select>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">性别</label>
            <div class="col-sm-2">
                <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('qdx_user_sex')}" th:field="*{sex}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:checked="${dict.dictValue == teacher.sex}"></option>
                </select>
            </div>
            <label class="col-sm-2 col-form-label text-sm-right">学历</label>
            <div class="col-sm-2">
                <select name="education" class="form-control m-b" th:field="*{education}">
                    <option value="">请选择学历</option>
                    <option value="研究生">研究生</option>
                    <option value="本科">本科</option>
                    <option value="大专">大专</option>
                    <option value="高中">高中</option>
                </select>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">专业</label>
            <div class="col-sm-2">
                <div class="input-group">
                    <select name="subjectId" class="form-control m-b">
                        <option value="">请选择专业</option>
                        <option th:each="subject : ${subjects}" th:text="${subject.subjectName}" th:value="${subject.subjectId}" th:selected="${teacher.subjectId == subject.subjectId}"></option>
                    </select>
                </div>
            </div>
            <label class="col-sm-2 col-form-label text-sm-right">职称</label>
            <div class="col-sm-2">
                <select name="starId" class="form-control m-b" th:with="type=${@dict.getType('qdx_teacher_title')}">
                    <option value="">请选择职称</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{starId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">简介</label>
            <div class="col-sm-8">
                <input id="intro" th:value="*{intro}" name="intro" type="hidden">
                <div id="editor"  class="summernote" th:text="*{intro}"></div>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label is-required text-sm-right">标签/研究方向</label>
            <div class="col-sm-5">
                <input name="tags" th:value="*{tags}" placeholder="请输入标签或研究方向" class="form-control" type="text">
            </div>
            <span class="form-text text-red pt-2">
                多个以豆号","分隔
            </span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label is-required text-sm-right">工作单位</label>
            <div class="col-sm-5">
                <input name="workUnit" th:value="*{workUnit}" placeholder="请输入所在工作单位" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label is-required text-sm-right">部门/院系</label>
            <div class="col-sm-5">
                <input name="workDept" th:value="*{workDept}" placeholder="请输入所在部门或院系" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label is-required text-sm-right">浏览量</label>
            <div class="col-sm-2">
                <input name="viewCount" th:value="*{viewCount}" class="form-control" value="0" type="text" required>
            </div>
            <label class="col-sm-2 col-form-label is-required text-sm-right">点赞数</label>
            <div class="col-sm-2">
                <input name="likeCount" th:value="*{likeCount}" class="form-control" value="0" type="text" required>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label is-required text-sm-right">排序</label>
            <div class="col-sm-2">
                <input name="sort" th:value="*{sort}" class="form-control" value="0" type="text" required>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label is-required text-sm-right">属性</label>
            <div class="col-sm-2 pt-2">
                <label for="isElite" class="text-primary"><input type="checkbox" value="1" name="isElite" id="isElite" th:checked="*{isElite==1}"> 推荐</label>
                &nbsp;&nbsp;&nbsp;
                <label for="isTop" class="text-danger"><input type="checkbox" value="1" name="isTop" id="isTop" th:checked="*{isTop==1}"> 固顶</label>
            </div>
            <label class="col-sm-2 col-form-label text-sm-right">&nbsp;</label>
            <label th:if="*{id >0 }" class="col-form-label col-sm-3 text-red" for="isDisabled">
                <input name="isDisabled" id="isDisabled" value="1" type="checkbox" th:checked="*{isDisabled==1}"> 禁用
            </label>
            <label th:if="*{id <=0 }" class="col-form-label col-sm-3 text-red" for="createManager">
                <input name="createManager" id="createManager" value="1" type="checkbox"> 创建管理账号
            </label>
        </div>
    </form>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: datetimepicker-js}" />
<th:block th:insert="~{include :: summernote-js}" />
<script src="/static/libs/layui-v2.6.8/layui.js?v=1"></script>
<script type="text/javascript">
    var prefix = "/teacher"

    $(function() {
        $("input[name='birthday']").datetimepicker({
            format: 'Y-m-d',
            yearStart: 1920, //设置最小年份
            yearEnd: 2025, //设置最大年份
            timepicker: false
        });

        $('#avatar-view').click(function () {
            $('#upload-avatar').click();
        });

        $('.summernote').summernote({
            placeholder: '请输入简介',
            height : 192,
            lang : 'zh-CN',
            followingToolbar: false,
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });
        var content = $("#intro").val();
        $('#editor').summernote('code', content);
    });

    function submitHandler() {
        var sHTML = $('.summernote').summernote('code');
        $("#intro").val(sHTML);
        $.operate.save("/teacher/save.json", $('#form-teacher-edit').serialize());
    }

    function ImgUpdate() {
        var file = $('#upload-avatar')[0].files[0];
        var formData = new FormData();
        formData.append("file", file);
        $.ajax({
            url: "/upload/temp/image.json",
            data: formData,
            type: "post",
            processData: false,
            contentType: false,
            dataType: "json",
            mimeType: "multipart/form-data",
            success: function (result) {
                if (result.code === 0) {
                    $("#avatar").val(result.data.src);
                    $("#avatar-view").attr("src", result.data.src);
                    window.layer.msg('上传成功', {icon: 1});
                } else {
                    window.layer.msg('上传失败', {icon: 2});
                }
            }
        })
    }

    // 上传文件
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: "/upload/image.json",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function(result) {
                if (result.code === 0) {
                    $(obj).summernote('editor.insertImage', result.data.src, result.data.title);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function(error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }
</script>
</body>
</html>